package com.lzh.base.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.HashSet;

/**
 * @author lzhstart
 * @create 2021/4/21 8:36
 */
@Configuration
@EnableSwagger2
@EnableKnife4j //启动knife4j动态参数
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {

    /***
     * 创建Docket
     */
    @Bean
    public Docket buildDocket(){
        //指定响应数据类型
        HashSet<String> produces = new HashSet<String>();
        produces.add("application/json");   //响应的数据格式为JSON格式
        return new Docket(DocumentationType.SWAGGER_2)
                //配置Swagger Api文档信息
                .apiInfo(buildApiInfo())
                .produces(produces)
                .select()
                //配置扫描的Controller包  com.lzh以及它所有子包
                .apis(RequestHandlerSelectors.basePackage("com.lzh"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置Swagger Api文档信息
     * @return
     */
    private ApiInfo buildApiInfo() {
        Contact contact = new Contact("lzh","","2784135960@qq.com");
        return new ApiInfoBuilder()
                .title("新梦想-平台管理API文档")
                .description("平台管理服务api")
                .contact(contact)
                .version("1.0.0")
                .build();
    }
}